package lab6.systemCustom;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ClientInput extends Thread {

	public void run() {
		try {
			BufferedReader objReader = new BufferedReader(new InputStreamReader(System.in));

			while (true) {
				EventBus.announce(EventBus.EV_SHOW, "\nSistem inscriere studenti\n");
				EventBus.announce(EventBus.EV_SHOW, "1) Lista studenti");
				EventBus.announce(EventBus.EV_SHOW, "2) Lista cursuri");
				EventBus.announce(EventBus.EV_SHOW, "3) Lista studentilor inscrisi la un curs");
				EventBus.announce(EventBus.EV_SHOW, "4) Lista cursurilor la care e inscris un student");
				EventBus.announce(EventBus.EV_SHOW, "5) Lista cursurilor absolvite de un student");
				EventBus.announce(EventBus.EV_SHOW, "6) Inscriere student la un curs");
				EventBus.announce(EventBus.EV_SHOW, "x) Exit");
				EventBus.announce(EventBus.EV_SHOW, "\nSelectati o optiune si apasati return >> ");
				String sChoice = objReader.readLine().trim();

				if (sChoice.equals("1")) {
					EventBus.announce(EventBus.EV_SHOW, "\n");
					EventBus.announce(EventBus.EV_LIST_ALL_STUDENTS, null);
					continue;
				}

				if (sChoice.equals("2")) {
					EventBus.announce(EventBus.EV_SHOW, "\n");
					EventBus.announce(EventBus.EV_LIST_ALL_COURSES, null);
					continue;
				}

				if (sChoice.equals("3")) {
					EventBus.announce(EventBus.EV_SHOW, "\nIndicati ID curs si apasati return >> ");
					String sCID = objReader.readLine().trim();

					EventBus.announce(EventBus.EV_SHOW, "\n");
					EventBus.announce(EventBus.EV_LIST_STUDENTS_REGISTERED, sCID);
					continue;
				}

				if (sChoice.equals("4")) {
					EventBus.announce(EventBus.EV_SHOW, "\nIndicati ID student si apasati return >> ");
					String sSID = objReader.readLine().trim();

					EventBus.announce(EventBus.EV_SHOW, "\n");
					EventBus.announce(EventBus.EV_LIST_COURSES_REGISTERED, sSID);
					continue;
				}

				if (sChoice.equals("5")) {
					EventBus.announce(EventBus.EV_SHOW, "\nIndicati ID student si apasati return >> ");
					String sSID = objReader.readLine().trim();

					EventBus.announce(EventBus.EV_SHOW, "\n");
					EventBus.announce(EventBus.EV_LIST_COURSES_COMPLETED, sSID);
					continue;
				}

				if (sChoice.equals("6")) {
					EventBus.announce(EventBus.EV_SHOW, "\nIndicati ID student si apasati return >> ");
					String sSID = objReader.readLine().trim();
					EventBus.announce(EventBus.EV_SHOW, "\nIndicati ID curs si apasati return >> ");
					String sCID = objReader.readLine().trim();

					// Verificarea suprasolicitarii cursului.
					EventBus.announce(EventBus.EV_CHECK_COURSE_OVERDEMAND, sCID);

					EventBus.announce(EventBus.EV_SHOW, "\n");
					EventBus.announce(EventBus.EV_REGISTER_STUDENT, "1 " + sSID + " " + sCID);
					continue;
				}

				if (sChoice.equalsIgnoreCase("X")) {
					break;
				}
			}

			objReader.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

}